package com.iptv.grape.event.imp;

import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.domain.AssetPlayData;
import com.iptv.grape.event.JSRequest;
import com.iptv.grape.event.msg.AssetPlayDataMsg;
import com.iptv.grape.event.msg.PlayRecordsFull;
import com.iptv.grape.event.proc.IWebViewMessageProc;
import com.iptv.grape.video.XMediaPlayer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// 获得当前的机顶盒播放记录
public class GetPlayRecords implements IWebViewMessageProc {
    @Override
    public void init(JSRequest jsRequest) {

    }

    @Override
    public String procMessage(BaseActivity baseActivity, XMediaPlayer mediaPlayer) {
        List<AssetPlayData> assetPlayDataList = GrapeContext.curGrapeContext().getAssetPlayDataList().getAll();
        List<AssetPlayDataMsg> list = new ArrayList<AssetPlayDataMsg>();
        for(int i = 0; i < assetPlayDataList.size(); i++){
            AssetPlayDataMsg msg = assetPlayDataList.get(i).toMsg();
            list.add(msg);
        }
        Collections.sort(list);
        PlayRecordsFull playRecordsFull = new PlayRecordsFull();
        playRecordsFull.setList(list);
        return new com.google.gson.Gson().toJson(playRecordsFull);
    }
}
